#import "BWThreadWindowController.h"
#import "BWColorset.h"
#import "BWAppController.h"

static BWThreadWindowController *g_controller;

@implementation BWThreadWindowController

// it's a global window, not needing any document-specific state

- (void) dealloc
{
    [colorsets release];
    [super dealloc];

} // dealloc


- (void) setSelectedManufacturerName: (NSString *) name
{
    [selectedManufacturerName release];
    selectedManufacturerName = [name copy];

    BWColorset *colorset;
    colorset = [[BWAppController globalController]
                   colorsetForManufacturerName: name];

    [colorsetController unbind: @"contentArray"];

    [colorsetController bind: @"contentArray"
                        toObject: colorset
                        withKeyPath: @"colors"
                        options: nil];

    [colorsetController rearrangeObjects];

    NSString *title;
    title = [NSString stringWithFormat: @"%@ Colors", name];

    [[self window] setTitle: title];

} // setSelectedManufactuerName


- (void) setColorsets: (NSArray *) c
{
    [self setSelectedManufacturerName:
              [[c objectAtIndex: 0]
                  valueForKey: @"manufacturerName"]];

    colorsets = [c retain];
    [manufacturersController setContent: colorsets];

} // setColorsets



+ (NSString *) autosaveName
{
    return (@"threadWindow");
} // autosaveName


+ (BWWindowController *) sharedInstance
{
    return (g_controller);
} // sharedInstance


+ (void) setSharedInstance: (BWWindowController *) controller
{
    assert ([[controller class] isSubclassOfClass: self]);

    g_controller = (BWThreadWindowController *)controller;

} // setShraedInstance


+ (NSString *) windowNibName
{
    return (@"BWThreadWindow");
} // windowNibName


- (NSString *) windowTitleForDocumentDisplayName: (NSString *) displayName
{
    return (@"Colors");

} // windowTitleForDocumentDisplayName


@end // BWThreadWindowController


